//
//  MZNSObjectDemoViewController.m
//  MZToolkitDemo
//
//  Created by shenjialin on 2017/4/17.
//  Copyright © 2017年 Chris Yang. All rights reserved.
//

#import "MZNSObjectDemoViewController.h"
#import "Observee.h"
#import "MZCategories.h"
#import "Class1516.h"
@interface MZNSObjectDemoViewController ()
{
    Observee *_observee;
}
@end

@implementation MZNSObjectDemoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _observee = [[Observee alloc] init];
    _observee.name = @"小明";
    _observee.age = 18;
    _observee.company = @"麦子金服";
    [_observee mzAddObserverForKeyPath:@"name" identifier:@"name" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld task:^(id obj, NSDictionary *change) {
        NSLog(@"%@",change);
    }];
    [_observee mzAaddObserverForKeyPaths:@[@"age",@"company"] identifier:@"ac" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld task:^(id obj, NSString *keyPath, NSDictionary *change) {
        NSLog(@"%@",change);
    }];
}
- (IBAction)changeName:(UIButton *)sender {
    _observee.name = [NSString stringWithFormat:@"%@%d",_observee.name,arc4random()%100];
}
- (IBAction)changeAge:(UIButton *)sender {
    _observee.age = arc4random()%100;
}
- (IBAction)changeCompany:(UIButton *)sender {
    _observee.company = [NSString stringWithFormat:@"%@%d",_observee.company,arc4random()%100];
    _observee=nil;
}

- (IBAction)saveClass:(UIButton *)sender {
    NSLog(@"%@",NSHomeDirectory());
    Class1516 *class1=[[Class1516 alloc]init];
    [class1 addStudentsWithName:@"曹孟德" age:15];
    [class1 addStudentsWithName:@"龙鹏" age:16];
    [class1 addStudentsWithName:@"乐乐" age:15];
    [self mzKeyedArchiverWithInfor:class1 withKey:@"class1"];
   
    Class1516 *class2=[[Class1516 alloc]init];
    [class2 addStudentsWithName:@"冯东升" age:15];
    [class2 addStudentsWithName:@"郑浩" age:16];
    [class2 addStudentsWithName:@"杨一凡" age:15];
    [self mzKeyedArchiverWithInfor:class2 withKey:@"class2"];
    
    Class1516 *class3=[[Class1516 alloc]init];
    [class3 addStudentsWithName:@"方树风" age:15];
    [class3 addStudentsWithName:@"朱晓超" age:16];
    [class3 addStudentsWithName:@"6哥" age:15];
    [self mzKeyedArchiverWithInfor:class3 withKey:@"class3"];
}

- (IBAction)readClass:(id)sender {
    Class1516 *class2= (Class1516 *)[self mzKeyedUnArchiverWithKey:@"class2"];
    [class2 showStudents];
}

- (IBAction)deleteClass:(UIButton *)sender {
    [self mzRemoveArchiveDataWithKey:@"class3"];
    
}

- (IBAction)deleteAllClass:(id)sender {
    [self mzRemoveAllArchiveData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
